from openpyxl.chart import *
from openpyxl import *


def separate_chart():
    """
    创建一个数据和图标分别在两个不同的工作表中。
    """
    wb = Workbook()
    data_sheet = wb.create_sheet('data', 0)
    chart_sheet = wb.create_sheet('chart', 1)

    for d in [[1,2,3], [4,5,6], [7,8,9]]:
        data_sheet.append(d)

    bar_chart = BarChart()
    data = Reference(data_sheet, min_col=1, max_col=data_sheet.max_column, min_row=1, max_row=data_sheet.max_row)
    label = Reference(data_sheet, min_col=1, max_col=1, min_row=1, max_row=data_sheet.max_row)
    bar_chart.add_data(data)
    bar_chart.set_categories(label)

    chart_sheet.add_chart(bar_chart)

    wb.save('g:\\test.xlsx')


if __name__ == '__main__':
    separate_chart()
